package com.qf.controller;

import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RestController
@RequestMapping("/test")
public class TestController {
    private RabbitTemplate rabbitTemplate;
    @Autowired
    public void setRabbitTemplate(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
    }
    @RequestMapping("/send")
    public String sendMessage(String message){
        String uuid=UUID.randomUUID().toString();
//        创建消息的唯一ID
        CorrelationData data=new CorrelationData(uuid);
        rabbitTemplate.convertAndSend("nazhejingzi", "", message,data);
        return "Rabbit 太难了"+uuid;
    }
}
